/**
 * 
 */
package com.cqrs.bey.ddd.impl;

import javax.inject.Inject;

import org.springframework.stereotype.Component;

import com.cqrs.bey.ddd.listener.DomainEventListener;

/**
 * @author Slawek
 */
@Component
public class EventRunEnvironment {

	public interface DomainEventListenerProvider {
		DomainEventListener<Object, Object> getHandler(Object domainEvent);
	}

	@Inject
	private DomainEventListenerProvider domainEventListenerProvider;

	public Object run(Object command) {
		DomainEventListener<Object, Object> handler = domainEventListenerProvider
				.getHandler(command);

		// You can add Your own capabilities here: dependency injection,
		// security, transaction management, logging, profiling, spying, storing
		// commands, etc

		Object result = handler.handle(command);

		// You can add Your own capabilities here

		return result;
	}

}
